import { IBulletConstructor } from "../interfaces/IBulletConstructor";

export class Bullet extends Phaser.GameObjects.Image {
    body: Phaser.Physics.Arcade.Body;

    private bulletSpeed: number;
    
    constructor(param: IBulletConstructor) {
        super(param.scene, param.x, param.y, param.texture);
        this.rotation = param.rotation;
        
        this.initImage();
        this.scene.add.existing(this);
    }

    private initImage() {
        this.bulletSpeed = 1000;
        // image config
        this.setOrigin(0.5, 0.5)
            .setDepth(2)
        ;

        // physics config
        this.scene.physics.world.enable(this);
        this.scene.physics.velocityFromRotation(
            this.rotation - Math.PI / 2, 
            this.bulletSpeed, 
            this.body.velocity
        );
    }

    update(...args: any[]): void {}
}